import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'iconfont  icon_menu_gzt_nor@2x icon_menu_gzt_nor2x' }
    }]
  },
  {
    path: '/information',
    component: Layout,
    redirect: '/information/index1',
    meta: { title: '基础信息管理', icon: 'iconfont con_menu_jcgl_nor@2x icon_menu_jcgl_nor2x' },
    children: [{
      path: 'index1',
      name: 'information',
      component: () => import('@/views/information/index'),
      meta: { title: '仓库管理' }
    },
    {
      path: 'addHouse',
      name: 'addHouse',
      component: () => import('@/components/addWareHouse'),
      meta: { title: '新增仓库' },
      hidden: true
    },
    {
      path: 'area',
      name: 'area',
      component: () => import('@/views/information/area'),
      meta: { title: '库区管理' }
    },
    {
      path: 'area/detial',
      name: 'detial',
      component: () => import('@/views/information/detial'),
      meta: { title: '新增库区' },
      hidden: true
    },
    {
      path: 'location',
      name: 'location',
      component: () => import('@/views/information/location'),
      meta: { title: '库位管理' }
    },
    {
      path: 'location/detail',
      name: 'locationDetail',
      component: () => import('@/views/information/components/locationDetail'),
      meta: { title: '新增库位' },
      hidden: true
    },
    {
      path: 'view',
      name: 'view',
      component: () => import('@/views/information/view'),
      meta: { title: '库位视图' }
    },
    {
      path: 'goods',
      name: 'goods',
      component: () => import('@/views/information/goods'),
      meta: { title: '货品管理' }
    },
    {
      path: 'type',
      name: 'type',
      component: () => import('@/views/information/type'),
      meta: { title: '货品类型管理' }
    }
    ]
  },
  {
    path: '/business',
    component: Layout,
    redirect: '/dashboard/index2',
    meta: { title: '商务管理', icon: 'iconfont   icon_menu_sygl_sel@2x icon_menu_sygl_sel2x' },
    children: [{
      path: 'index2',
      name: 'index2',
      component: () => import('@/views/business/index'),
      meta: { title: '货主管理' }
    },
    {
      path: 'carrier',
      name: 'carrier',
      component: () => import('@/views/business/carrier'),
      meta: { title: '承运商管理' }
    }
    ]
  },
  {
    path: '/Inventory',
    component: Layout,
    redirect: '/Inventory/index3',
    meta: { title: '库内管理', icon: 'iconfont icon_menu_kngl_nor@2x icon_menu_kngl_nor2x' },
    children: [{
      path: 'index3',
      name: 'index3',
      component: () => import('@/views/Inventory/index'),
      meta: { title: '盘点单' }
    },
    {
      path: 'checkTask',
      name: 'checkTask',
      component: () => import('@/views/Inventory/checkTask'),
      meta: { title: '盘点任务' }
    },
    {
      path: 'increaseDecrease',
      name: 'increaseDecrease',
      component: () => import('@/views/Inventory/increaseDecrease'),
      meta: { title: '库存损益' }
    },
    {
      path: 'realTime',
      name: 'realTime',
      component: () => import('@/views/Inventory/realTime'),
      meta: { title: '实时库存' }
    }

    ]
  },
  {
    path: '/Warehousing',
    component: Layout,
    redirect: '/Warehousing/index4',
    meta: { title: '入库管理', icon: ' iconfont icon_menu_rkgl_nor@2x icon_menu_rkgl_nor2x' },
    children: [{
      path: 'index4',
      name: 'index4',
      component: () => import('@/views/Warehousing/index'),
      meta: { title: '入库单' }
    },
    {
      path: 'receiving',
      name: 'receiving',
      component: () => import('@/views/Warehousing/receiving'),
      meta: { title: '收货任务' }
    },
    {
      path: 'grounding',
      name: 'grounding',
      component: () => import('@/views/Warehousing/grounding'),
      meta: { title: '上架任务' }
    }
    ]
  },
  {
    path: '/outbound',
    component: Layout,
    redirect: '/outbound/index5',
    meta: { title: '出库管理', icon: 'iconfont  icon_menu_ckgl_nor@2x icon_menu_ckgl_nor2x' },
    children: [{
      path: 'index5',
      name: 'index5',
      component: () => import('@/views/outbound/index'),
      meta: { title: '出库单' }
    },
    {
      path: 'picking',
      name: 'picking',
      component: () => import('@/views/outbound/picking'),
      meta: { title: '拣货任务' }
    },
    {
      path: 'handover',
      name: 'handover',
      component: () => import('@/views/outbound/handover'),
      meta: { title: '交接任务' }
    }

    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
